package cn.lvji.springboot.learn.exception.conf;

import cn.lvji.springboot.learn.exception.exception.MyException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

//@RestControllerAdvice
@Component
public class MyControllerAdvice { //} extends ResponseEntityExceptionHandler {

    @ExceptionHandler(NullPointerException.class)
    public String arithException(){
        return "arith error";
    }

    @ExceptionHandler(MyException.class)
    public String myException(MyException e, HttpServletRequest request,HttpServletResponse response){
        request.getRequestURI();
        e.printStackTrace();
        response.setStatus(400);
        return "myException";
    }
}
